var username = getCookie("username");
var li = document.querySelector(".header-con li:first-child");
// console.log(li);
if (username) {
    li.innerHTML = "";
    var str = `
            欢迎${username}光临
            <a href="javascript:;" class="del">退出</a>
    `;
    li.innerHTML = str;
    var del = document.querySelector(".del");
    del.onclick = function () {
        removeCookie("username");
        li.innerHTML = "";
        var str = `
            <a href="login.html" id="login">登陆</a>
            <a href="register.html" id="register">注册</a>
        `;
        li.innerHTML = str;
    }
}

var index;
$.ajax({
    url: "./serve/list.php",
    method: "post",
    dataType: "json",
    beforeSend:function() {
        index = layer.msg('玩命加载中...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,offset: '0px', time:100000});
    },
    success: function (res) {
        // console.log(res);
        layer.close(index);
        var str = "";
        for (var i = 0; i < res.length; i++) {
            str += `
                <article class="white-panel">
                    <img src="${res[i].imgpath}" class="thumb">
                    <h1><a href="#">${res[i].name}</a></h1>
                    <p>${res[i].introduce}</p>
                    <p>￥${res[i].price}元</p>
                    <p>
                       <a href = "detail.html?id=${res[i].id}" class="btn btn-info">详情</a>
                    </p>
                    
                </article>
            `
            $("#gallery-wrapper").html(str);
        }
    }
})